<?php
require '../nette.min.php';
Nette\Diagnostics\Debugger::enable();
Nette\Diagnostics\Debugger::$strictMode = TRUE;
require '../loader.php';
WDB\Config::$source = __DIR__. '/../demos/pujcovna/config.php';

//$twa = \WDB\WebUI\Table::forTableName('zavodnik');
//$passwordCheck = new WDB\WebUI\ColumnPasswordCheck($twa,'Heslo znovu:', 'password', 'passwordCheck');
//$twa->addColumn($passwordCheck);
//$twa->columns['password']->setDisplayModes(\WDB\WebUI\iColumn::DISPLAY_EDIT);

//$twa->order('jmeno', 'grp');

//$wa = \WDB\WebUI\Schema::forSchemaName('te.st ššš');
/**@var $table WDB\Wrapper\TimeDependentTable */
$table = WDB\Wrapper\TableFactory::fromName('zakaznici');

echo $table->getRecordByKeyForTime(time()-10*86400, 1)['adresa'].'<br>';
foreach ($table->getRecordTimeSpanList(1) as $ts)
{
    echo $ts->id.': '.$ts->from->format('j.n.Y').' '.$ts->to->format('j.n.Y').'<br>';
}

$rec = $table->getRecordByKeyForTime(time()-15*86400, 1);
//var_dump($rec['id~td']);die();
//var_dump($rec->getFromGlobal());
//var_dump($rec->getToGlobal());
$rec->setGlobalTimespan('2012-01-01', '2014-05-30');
$rec->setGlobalTimespan(NULL, NULL);
$rec->setTimespan('2013-05-31', '2013-06-10');
var_dump($rec->save());

die();
$rec['adresa'] = 'jinde'.rand(1,1000);
$rec['telefon'] = rand(1,100000);
$rec->save();

$zakaznik = $table->newRecord();
$zakaznik['adresa'] = 'vsude';
$zakaznik['telefon'] = '667';
$zakaznik['jmeno'] = 'Novacek';
$zakaznik['mail'] = 'novacek@example.com';
$zakaznik['datum_narozeni'] = new \DateTime('1.5.1990');
$zakaznik->save();
echo $zakaznik['id_zakaznik'].'/'.$zakaznik['id~td'];
